import { ppid } from "process";

// 交叉类型（Intersection Types）: 交叉类型是将多个类型合并为一个类型
interface IPerson {
  name: string;
  age: number;
  sex?: {
    name: "男" | "女";
  };
}

interface Money {
  money: number;
  makeMoney: (num: number) => void;
}

const o: IPerson & Money = {
  name: "张三",
  age: 18,
  money: 123,
  makeMoney(num: number) {
    this.money += num;
  },
};
// 联合类型（Union Types) : 联合类型表示一个值可以是几种类型之一
const o1: IPerson | Money = {
  // name: "张三",
  // age: 18,
  money: 123,
  makeMoney(num: number) {
    // (o1 as Money).money += num;

    // (<Money>o1).money += num;
		// return (
			
			// <div>
			// 	// {  (<Money>o1).money }
			// </div>
		// )
  },
};

// 类型保护
const xx: number | string | null = 123;

// 类型保护
if (typeof xx === "number") {
  const b = xx + 1;
}

if (xx !== null) {
}

const oo: IPerson = {
  name: "李四",
  age: 18,
  sex: {
    name: "男",
  },
};
// if (typeof oo.sex !== 'undefined') {
oo.sex!.name = "女";
// }
